package cn.com.fssg.platform.base.handler.impl.zynlpg;

import cn.com.fssg.platform.base.handler.InterfaceHandler;
import cn.com.fssg.platform.biz.BizUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * @Description: 我的商协会查询表单数据
 */
@Component
public class DimensionSelection implements InterfaceHandler {

//    @Autowired
//    private NamedParameterJdbcTemplate jdbcTemplate;
    private NamedParameterJdbcTemplate jdbcTemplate = BizUtil.cur().tenantMainJdbcTemplate();

    @Override
    public Object run(HttpServletRequest request, JSONObject jsonObject) throws Exception {
        String sql = "SELECT DISTINCT classification FROM dimension";
        List<Map<String, Object>> classList = jdbcTemplate.queryForList(sql, jsonObject);
        Map map = new HashMap();
        List dimensionList = new ArrayList();
        for (Map<String, Object> objectMap : classList){
            String c = objectMap.get("classification").toString();
            jsonObject.put("classification", c);
            sql = "select * from dimension where classification = :classification";
            List<Map<String, Object>> entityList = jdbcTemplate.queryForList(sql, jsonObject);
            dimensionList.add(entityList);
            map.put(c,entityList);
        }
        Map result = new HashMap();
        result.put("classList",classList);
        result.put("dimensionList",dimensionList);
        return result;
    }
}
